package leetcode;

import java.util.ArrayList;
import java.util.List;

public class _0199 {
    /**
     *二叉树的右视图
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    class Solution {
        private final ArrayList<Integer> ans = new ArrayList<>();

        public List<Integer> rightSideView(TreeNode root) {
            dfs(root,0);
            return ans;
        }
        public void dfs(TreeNode root, int depth){
            if(root ==null){
                return;
            }
            if(depth==ans.size()){
                ans.add(root.val);
            }
            dfs(root.right,depth+1);
            dfs(root.left,depth+1);
        }
    }
}
